﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.IO;

public partial class test_frameset : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Dictionary<string, string> userList = Application.Get("GLOBAL_USER_LIST") as Dictionary<string, string>;
        if (userList != null)
        {
            foreach (var item in userList)
            {
                if (item.Key != null && String.Compare(item.Key, Session.SessionID) == 0)
                {
                    if (item.Value != null && String.Compare("useronline", item.Value) == 0)
                    {
                        userList.Remove(Session.SessionID);
                        Application.Lock();
                        Application.Add("GLOBAL_USER_LIST", userList);
                        Application.UnLock();
                        Response.Write("<script type='text/javascript'>alert('您的账号已经在其他地方登录,您被强制下线');window.location='../logout_close.aspx';window.parent.opener.parent.location='../index.aspx';window.parent.close();</script>");
                    }
                    break;
                }
            }
        }
        //if (!IsPostBack)
        //{
        //    getBgImg();
        //}
    }
    ///// <summary>
    ///// 获取自定义背景图片
    ///// </summary>
    ///// <returns></returns>
    //public string getBgImg()
    //{
    //    string sql = string.Format("select BeiJing from JiGouPeiZhi where JiGouMingCheng='{0}'", Session["sJiGou"].ToString());
    //    DataTable dt = DbHelper.ExecuteTable(CommandType.Text, sql, null);
    //    if (dt.Rows.Count == 1)
    //    {
    //        string imgPath = dt.Rows[0]["BeiJing"].ToString();
    //        if (!File.Exists(MapPath(imgPath)))
    //        {
    //            ViewState["bg"] = null;
    //        }
    //        else
    //        {
    //            ViewState["bg"] = imgPath;
    //        }
    //    }
    //    else
    //    {
    //        ViewState["bg"] = null;
    //    }
    //}
    /// <summary>
    /// 获取自定义背景图片
    /// </summary>
    /// <returns></returns>
    public string getBgImg()
    {
        string sql = string.Format("select BeiJing from JiGouPeiZhi where JiGouMingCheng='{0}' and beijingqiyong=1", Session["sJiGou"].ToString());
        DataTable dt = DbHelper.ExecuteTable(CommandType.Text, sql, null);
        if (dt.Rows.Count == 1)
        {
            string imgPath = dt.Rows[0]["BeiJing"].ToString();
            if (!File.Exists(MapPath("../" + imgPath)))
            {
                return "../images/bg.jpg";
            }
            else
            {
                return "../" + imgPath;
            }
        }
        else
        {
            return "../images/bg.jpg";
        }
    }
}
